import socket,select

add2 = ('42.51.28.250',12769)
add3 = ('45.8.159.202',12769)
peer_ip = '103.235.228.192'
import time
add = ('0.0.0.0',10000)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)    
s.bind(add)

s.sendto(b'aax',add2)
s.sendto(b'aax',add3)


g_a = None
m = {}


while True:
   
    for i in range(10000,60000):
        
        if i%10000==0:
            print(i)
            
        time.sleep(0.001)
        if g_a:
            time.sleep(1)
        add = (peer_ip,i)
        if g_a:
            add = g_a
        s.sendto(bytes(str(time.time()),encoding='utf8'),add)
        while True:
            r,w,e = select.select([s],[],[],0.001)
            if not r:
                break
            a = s.recvfrom(10000)
            print('got',a)
            dd = a[1]
            if dd not in m:
                m[dd]=0
            m[dd] += 1
            if m[dd] ==3 :
                g_a = a[1]
                
            
            
